﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using FT.Commons.Win32;

namespace ShopAdForm.Controls
{
    public partial class ShopTypeVerticalPanel : FT.TouchScreen.Terminal.Controls.DragPanel
    {
        public ShopTypeVerticalPanel()
        {
            InitializeComponent();
        }

        public void InitShopType()
        {
            //ShopTypeButton btnTrue = null;
            PictureBox btnTrue = null;
            int top = 10;
            int sep = 10;
            int x = (this.Width - 150) / 2;
            DataTable dt = FT.DAL.DataAccessFactory.GetDataAccess().SelectDataTable("select id,name,img from navigate_shop_types", "tmp");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                btnTrue = new PictureBox();
                btnTrue.Width = 150;
                btnTrue.Height = 40;
                string img=dt.Rows[i]["img"].ToString();
                string path=Application.StartupPath+"\\"+img;
                if (System.IO.File.Exists(path))
                    btnTrue.Image = Image.FromFile(path);
               // btn.ShopTypeText = "商户类型" + i.ToString();
                btnTrue.Tag = dt.Rows[i]["id"].ToString();
               // btn.Click += new EventHandler(btn_Click);
                //btnTrue.Click += new EventHandler(btnTrue_Click);
                btnTrue.MouseDown += new MouseEventHandler(btnTrue_MouseDown);

                btnTrue.Location = new Point(x, top + i * btnTrue.Height + i * sep);
                this.AddControl(btnTrue);

            }
            this.Height = top + 15 * 50 + 10;
            this.Location = new Point(0, 0);
        }

        void btnTrue_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                Control ctr=sender as Control;
                DiscountPanel discountPanel1 = (DiscountPanel)this.FindForm().Controls["discountPanel1"];
                discountPanel1.SetDiscountType(Convert.ToInt32(ctr.Tag));
                discountPanel1.BringToFront();
            }
            //throw new NotImplementedException();
        }

        void btnTrue_Click(object sender, EventArgs e)
        {
           
           // throw new NotImplementedException();
        }

        public void InitMockShopType()
        {
            ShopTypeButton btn = null;
            int top = 10;
            int sep = 10;
            int x = (this.Width - 100) / 2;
            for (int i = 0; i < 15; i++)
            {
                btn = new ShopTypeButton();
                btn.Width = 100;
                btn.Height = 40;
                btn.ShopTypeText = "商户类型" + i.ToString();
                btn.Tag = i;
                btn.Click += new EventHandler(btn_Click);
                
                btn.Location = new Point(x, top + i * btn.Height+i*sep);
                this.AddControl(btn);

            }
            this.Height = top + 15 * 50 + 10;
            this.Location = new Point(0,0);
        }

        void btn_Click(object sender, EventArgs e)
        {
            Control ctr = sender as Control;
            MessageBox.Show("点击了商户类型"+ctr.Tag.ToString());
            //throw new NotImplementedException();
        }


       // private MousePreview m_MousePreview;


        private void ShopTypeVerticalPanel_Load(object sender, EventArgs e)
        {
             if (!this.DesignMode)
            {
                //m_MousePreview = new MousePreview(this.label1);

            }
        }
    }
}
